<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>局域网文件分享</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend >局域网文件分享</legend>
</fieldset>
<span class="layui-breadcrumb" lay-separator=">">
  <a href="/index" class="layui-btn layui-btn-lg layui-btn-primary layui-btn-radius">ROOT</a>

</span>
<table  class="layui-table"  lay-size="lg" lay-even>
    <colgroup>
        <col>
        <col>
        <col>
    </colgroup>
    <thead>
    <tr>
        <th>文件名</th>
        <th>文件类型</th>
        <th>文件大小</th>
    </tr>
    </thead>
    <tbody id="tbody">
    </tbody>
</table>
 <input type="hidden" id="code" th:value="${code}"/>


<script src="/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['element', 'layer'], function () {
        var element = layui.element
            , $ = layui.$
             , layer = layui.layer;

        window.gotovideo  = function(e) {
            var isfile = $(e).attr('isfile')=="true";
            if(isfile){
                location.href=encodeURI("/fileDetailPage?code="+$(e).attr('id'));
            }else{
                location.href=encodeURI("/index?code="+$(e).attr('id'));
            }
        }


        function init(code) {
            var config = {
                type: "post",
                url: "/file",
                async: true,
                data: {"path": code},
                success: function (data) {
                    if(data.code!=0){layer.msg("不存在的文件/文件夹");return;}
                    var res = data.data;
                      var html = "";
                    for (var index in res) {
                        var item = res[index];
                        html += '<tr  isfile="'+item.isFile+'"  id="' + item.path.substring(item.path.indexOf("///")+3) + '" onclick="gotovideo(this)">' +
                            '        <td>' + item.name + '</td>' +
                            '        <td>' + item.type + '</td>' +
                            '        <td>' + parseInt(item.length / 1024 /1024) + 'M</td>' +
                            '    </tr>';
                    }
                    $('#tbody').html(html);

                    var html = "",path="";
                    for(var index in code.split("/")){
                        if(code.split("/")[index]==""){break;}

                        path+= code.split("/")[index]+"/";
                         html+='<a href="/index?code='+path+'" class="layui-btn layui-btn-lg layui-btn-primary layui-btn-radius">'+code.split("/")[index]+'</a>';
                    }
                     $('.layui-breadcrumb').append(html);
                    element.init();
                 }
            };
            $.ajax(config);
        }
        init($('#code').val());
    });
</script>

</body>
</html>